package com.investmenttechnologyservices.model;

import java.util.Date;
import java.util.StringTokenizer;
import java.util.logging.Logger;

import org.mortbay.log.Log;

import com.investmenttechnologyservices.services.EntityTestService;
import com.investmenttechnologyservices.util.DateUtil;


public class QuoteRTListed {
	private String symbolId;
	private Date quoteDate ;
	private Double last;
	private Double open;
	private Double bid;
	private Double ask;
	private Long volume;
	private Double change;

	private static final Logger log = Logger.getLogger(QuoteRTListed.class.getName());

	public QuoteRTListed() {
	}

	public QuoteRTListed(String s) {
		String t;
		log.info("[QuoteRTListed(in): s="+s);
		StringTokenizer st = new StringTokenizer(s, ",");
		Integer i = st.countTokens();
		if (i==9) {
			setSymbolId(getSymbol(st));
			setLast(getPrice(st));
			if (getLast()!=0.0) {
				setQuoteDate(new Date());
				t=getSymbol(st); 
				t=getSymbol(st); 
				setChange(getPrice(st));
				if (getChange()!=0.0) {
					setOpen(getPrice(st));
					setBid(getPrice(st));
					setAsk(getPrice(st));
					setVolume(getLong(st));
				}
			}
		}
	}
	
	public void setSymbolId(String symbolId) {this.symbolId=symbolId;}
	public String getSymbolId() {return symbolId;}
	
	public void setQuoteDate(Date quoteDate) {this.quoteDate=quoteDate;}
	public Date getQuoteDate() {return quoteDate;}

	public void setLast(Double last) {this.last=last;}
	public Double getLast() {return last;}

	public void setChange(Double change) {this.change=change;}
	public Double getChange() {return change;}

	public void setOpen(Double open) {this.open=open;}
	public Double getOpen() {return open;}

	public void setBid(Double bid) {this.bid=bid;}
	public Double getBid() {return bid;}

	public void setAsk(Double ask) {this.ask=ask;}
	public Double getAsk() {return ask;}

	public void setVolume(Long volume) {this.volume=volume;}
	public Long getVolume() {return volume;}

	private static String getSymbol(StringTokenizer st) {
		String s = null;
		try {
			s = st.nextToken();
		} catch (Exception e) {
			return "";
		}
		return s.trim();
	}
	
	private Double getPrice(StringTokenizer st) {
		final String s = getSymbol(st);
		Double result = 0.0;
		try {
			result = Double.valueOf(s).doubleValue();
		}
		catch (NumberFormatException ex) {
			ex.printStackTrace();
		}
		return result;
	}
	
	private static Long getLong(StringTokenizer st) {
		final String s = getSymbol(st);
		Long l = 0L;
		try {
			l = Long.valueOf(s).longValue();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return l;
	}


}
